<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add">新增品牌间隔</button>
                <!--                <button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="delete"> 删除 </button>-->
            </div>
        </script>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
    </div>
</div>
<script src="../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            laydate = layui.laydate,
            roleType = layui.data("user").roleType,
            table = layui.table;

        table.render({
            elem: '#currentTableId',
            // url: '../api/user.json',
            url: '/zxjy/brand/list/' + roleType.toLowerCase(),
            toolbar: roleType === "SUPERVISOR" ? '#toolbarDemo' : '',
            method: 'post',
            contentType: 'application/json',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cellMinWidth: 100,
            cols: [[
                // {field: 'id', width: 80, title: 'ID'},
                {field: 'brandTypeName', title: '品牌'},
                {field: 'startTime', title: '启用开始时间'},
                {field: 'endTime', title: '启用结束时间'},
            ]],
            response: {statusCode: 200},
            parseData: function (res) { //将原始数据解析成 table 组件所规定的数据
                return {
                    "code": res.state, //解析接口状态
                    "msg": res.success, //解析提示文本
                    "count": res.result.total, //解析数据长度
                    "data": res.result.list //解析数据列表
                };
            },
            request: {
                pageName: 'pageNum' // 页码的参数名称，默认：page
                , limitName: 'pageSize' //每页数据量的参数名，默认：limit
            },
            limits: [10, 15, 20, 25, 50, 100],
            limit: 10,
            page: true,
            skin: 'line'
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            // var result = JSON.stringify(data.field);
            // layer.alert(result, {
            //     title: '最终的搜索信息'
            // });

            //执行搜索重载
            table.reload('currentTableId', {
                url: '/zxjy/brand/list/supervisor'
                ,where: {
                    wechatNo: data.field.wechatNo,
                    phone: data.field.phone,
                    nickname: data.field.nickname,
                    highSeasStatus: data.field.highSeasStatus,
                } //设定异步数据接口的额外参数
            });


            //执行搜索重载
            // table.reload('currentTableId', {
            //     page: {
            //         curr: 1
            //     }
            //     , where: {
            //         wechatNo: result.wechatNo
            //     }
            // }, 'data');
            return false;
        });

        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            layer.open({
                title: '新增',
                type: 2,
                shadeClose: true,
                offset: '150px',
                area: ['550px', '500px'],
                content: '../page/table/addbrandduration.html'
            });
        });

    });
</script>

</body>
</html>
